package views
{
	import com.oosterwijk.irc.User;
	
	import flash.text.*;
	
	import qnx.ui.core.Container;
	import qnx.ui.core.ContainerFlow;
	import qnx.ui.core.SizeUnit;
	import qnx.ui.listClasses.AlternatingCellRenderer;
	import qnx.ui.skins.*;
	import qnx.ui.text.Label;
	
	public class UserListRenderer extends AlternatingCellRenderer
	{
		private var _prefix:Label;
		private var _userName:Label;
		private var selectedFont:TextFormat;
		private var unselectedFont:TextFormat;
		
		public function UserListRenderer()
		{
			this.label.visible = false;
		}
		override protected function init():void
		{
			super.init();
			
			selectedFont =   new TextFormat("Courier New", 18, 0xFFFFFF);
			unselectedFont = new TextFormat("Courier New", 18, 0x0C0E10);
			
			setTextFormatForState(unselectedFont, SkinStates.UP);
			setTextFormatForState(selectedFont, SkinStates.DOWN);
			setTextFormatForState(selectedFont, SkinStates.SELECTED);
			setTextFormatForState(unselectedFont, SkinStates.DISABLED);
			
			_userName = new Label();
			_userName.x = 35;
			_userName.width = 200;
			addChild(_userName);
			
			_prefix = new Label();
			_prefix.x = 5;
			
			addChild(_prefix);
		}

		override public function set data(data:Object):void
		{
			super.data= data;
			if( data ){
				//var user:User = data as User;
				this._userName.text = data.nick;
				this._prefix.text = data.prefix;
			}
		}
		
		override protected function setLabelState(state:String):void
		{
			var format:TextFormat = getTextFormatForState(state);
			if(format != null){
				if(_prefix)_prefix.format = format;
				if(_userName)_userName.format = format;
			}
		}
	}
}